<% layout('/layouts/default.html', {title: '考核任务指标表管理', libs: ['dataGrid','fileupload','validate']}){ %>
<div class="main-content">
    <div class="box box-main">
        <div class="box-header">
            <div style="float: left">
                <div class="form-group">
                    <button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('返回')}</button>
                </div>
            </div>
            <#form:form id="searchForm" model="${dcSupExamSumQuotaInfo!}" action="${ctx}/quota/dcSupExamSumQuotaInfo/listDetailFileData?sumQuotaId=${dcSupExamQuota.id}&quotaGroup=2&exameOrg=${dcSupExamQuota.createOrg}" method="post" class="form-inline "
            data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
            <div style="float: right">

<!--                <div class="form-group">-->
<!--                    <button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>-->
<!--                    <button onclick="cz();" class="btn btn-default btn-sm">${text('重置')}</button>-->
<!--                </div>-->
            </div>
        </#form:form>

    </div>
    <div class="box-body" >

        <div style="float: left;">
            <div class="form-group">
                <label class="blue " >${text('指标细则')}</label>
            </div>
        </div>
        <div style="float: right;" id="tijiao">
            <a href="#"   onclick="updateInfo()" class="btn btn-primary btn-sm mr10 mb10" style="background-color:#00B7EE;border-color: #00b7ee;margin-left: 10px" title="${text("提交")}"> 提交</a>
        </div>
    </div>
    <#form:form id="inputForm" model="${dcSupExamQuota}" action="${ctx}/quota/dcSupExamQuota/save" method="post" class="form-horizontal">
    <div class="box-body">

        <table id="dataGrid"></table>
        <div id="dataGridPage"></div>
    </div>

</div>

</div>
</#form:form>
<% } %>
<script src="${ctxStatic}/m/js/total.js?${_version}"></script>
<script>
    // 初始化DataGrid对象
    $('#dataGrid').dataGrid({
        searchForm: $("#searchForm"),
        columnModel: [
            {header:'${text("目标内容")}', name:'ids',  hidden:true},
            {header:'${text("指标名称")}', name:'quotaContent',  width:250, align:"left"},
            {header:'${text("被考核单位")}', name:'orgName',  width:250, align:"left"},
            {header:'${text("上传细则")}', name:'fileuploadId', width:150,align:"center",
                editable: true, edittype: "custom", editoptions: {
                    custom_element: function(val, editOptions) {
                        return js.template('fileuploadTpl', {
                            id: 'fileupload_'+editOptions.id, title: '区域选择',
                            bizKey: val, bizType: 'dcSupExamSumQuotaInfo_file', cssClass: '', readonly: false
                        });
                    }
                },unformat: function(val, obj, cell){
                    return $('#fileupload_'+obj.rowId+'_fileuploadId', cell).val();}
            },
        ],
        editGrid: true,
        showFooter: true, // 是否显示底部合计行
        autoGridHeight: function(){return 500},
        // 加载成功后执行事件
        ajaxSuccess: function(data){
            refreshZpCount()
        }
    });


    function updateInfo() {
        var flag = true;
        $.each($('#dataGrid').dataGrid('getRowData'), function (i, item) {
            if (!item.fileuploadId) {
                flag = false;
                js.showMessage("提交失败目标内容：" + item.quotaContent + "请先上传考核细则")
                return false;
            }
            if(($("#"+i+"_fileuploadId "+".statusBar .info").text().indexOf("上传失败"))!=-1){
                js.showMessage("第"+i+"行"+$(".statusBar .info").text());
                return false;
            }
        })
        if (flag){
            let allData = JSON.stringify($('#dataGrid').dataGrid('getRowData'));
        let dcSupExamSumQuotaInfoList = {"dcSupExamSumQuotaInfoList": allData}
        js.ajaxSubmit({
            url: "${ctx}/quota/dcSupExamSumQuotaInfo/saveStrFile?noticeId=${dcSupExamQuota.noticeId!}",
            data: dcSupExamSumQuotaInfoList,
            dataType: 'json',
            callback: function (data) {
                if (data.result == "true") {
                    js.showMessage(data.message);
                    js.closeCurrentTabPage(function(contentWindow){
                        contentWindow.page();
                    });
                } else {
                    js.showMessage(data.message);
                }
            }
        })
      }
    }
    function cz(){
        searchForm.reset();
        $('#dataGrid').dataGrid('reloadGrid');
    }
</script>
<script id="fileuploadTpl" type="text/template">//<!--<div>
<#form:fileupload id="{{d.id}}" bizKey="{{d.bizKey}}" bizType="{{d.bizType}}" uploadType="all"
	class="{{d.cssClass}}" maxUploadNum="1"  isMini="true" preview="true" readonly="{{d.readonly}}"/>
</div>//--></script>